//
// Created by 张易生 on 2022/1/12.
//

#ifndef ZYSPLAYER_ZYSFFMPEG_H
#define ZYSPLAYER_ZYSFFMPEG_H


#include "ZYSPlayStatus.h"
#include "pthread.h"
#include "ZYSAudioPlayer.h"
#include "ZYSVideoPlayer.h"
#include "ZYSCallJava.h"

extern "C"
{
#include "libavformat/avformat.h"
#include "libavutil/time.h"
};

class ZYSFFmpeg {
public:
    ZYSCallJava *callJava = NULL;
    const char* url = NULL;
    pthread_t decodeThread;
    AVFormatContext *avFormatCtx = NULL;
    ZYSAudioPlayer *audioPlayer = NULL;
    ZYSVideoPlayer *videoPlayer = NULL;
    ZYSPlayStatus *playStatus = NULL;
    //总时长
    int duration = 0;
    //seek时的线程
    pthread_mutex_t init_mutex;
    pthread_mutex_t seek_mutex;
    bool exit = false;
public:
    ZYSFFmpeg(ZYSPlayStatus *playStatus, ZYSCallJava *callJava, const char *url);

    ~ZYSFFmpeg();

    void prepared();

    int getCodecContext(int type,AVCodecParameters *codecpar, AVCodecContext **avCodecContext);
    void decodeFFmpegThread();

    void releaseFormatContext();

    void startDecode();

    void pause();

    void resume();

    void seek(int64_t second);

    void setMute(int mute);

    void setVolume(int percent);

    //倍速
    void setSpeed(float speed);
    //变音调
    void setPitch(float pitch);

    void release();

    void startAVDecode_cpp();
//    void startAudioDecode_cpp();
};


#endif //ZYSPLAYER_ZYSFFMPEG_H
